#include "utils/format_time.h"

/** 从模块返回数据中获取年-处理数据格式 */
uint8_t formatWithTmYear(AtNetworkStream *stream) {
  int v = stream->streamGetInt(8, '/');
  if (v > 99 && v <= 9999) {
    return v - 1900;
  }
  if (v > 0 && v <= 99) {
    return v + 100;
  }

  return 0;
}

/** 从模块返回数据中获取月-处理数据格式 */
uint8_t formatWithTmMonth(AtNetworkStream *stream) {
  int v = stream->streamGetInt(4, '/');
  if (v > 0 && v <= 12) {
    return v - 1;
  }

  return 0;
}

/** 从模块返回数据中获取日-处理数据格式 */
uint8_t formatWithTmDay(AtNetworkStream *stream) {
  int v = stream->streamGetInt(4, ',');
  if (v > 0 && v <= 31) {
    return v;
  }

  return 0;
}

/** 从模块返回数据中获取时-处理数据格式 */
uint8_t formatWithTmHour(AtNetworkStream *stream) {
  int v = stream->streamGetInt(4, ':');
  if (v > 0 && v <= 24) {
    return v;
  }

  return 0;
}

/** 从模块返回数据中获取分-处理数据格式 */
uint8_t formatWithTmMin(AtNetworkStream *stream) {
  int v = stream->streamGetInt(4, ':');
  if (v > 0 && v <= 60) {
    return v;
  }

  return 0;
}

/** 从模块返回数据中获取秒-处理数据格式 */
uint8_t formatWithTmSec(AtNetworkStream *stream) {
  int v = stream->streamGetInt(4, '+');
  if (v > 0 && v <= 60) {
    return v;
  }

  return 0;
}
